var lpxqApp = function() {

	var dwArr = [ "School coin", "Score" ];

	var lpid = manager.findParamFromUrl("lpid");

	var ywy = manager.findParamFromUrl("ywy");

	var picControl = "";

	var selectKey = "1";

	var img = Constants.imgUrl;
	// 初始化图片
	function initCpic(picnum, selectKey) {
		var controlPicture = {
			getPage : 1,
			curPic : selectKey,
			picnum : picnum,
			moveTimer : "",
			loadAllThumb : false,
			playTime : 10000,
			playState : true,
			isPlaying : false,
			changeList : function(f, c) {
				var b = this.getPage;
				var d = this.picnum;
				if (d > 4) {
					var e = 90;
					b = parseInt(b);
					if (typeof (c) != "undefined") {
						b = parseInt(c);
						if (b < 1) {
							b = 1
						}
						if (b > d - 5) {
							b = d - 5
						}
					} else {
						if ("1" == f) {
							b = b + 4;
							if (b > (d - 3)) {
								b = d - 3
							}
						} else {
							b = b - 4;
							if (b < 1) {
								b = 1
							}
						}
					}
					this.getPage = b;
					var a = (b - 1) * e;
					$(".gallery_demo_unstyled").animate({
						left : -a
					}, {
						queue : false
					});
				}
			},
			selectByurl : function() {
				var b = window.location.href;
				var a = b.split("#");
				if (typeof (a[1]) != "undefined") {
					var c = a[1].split("=");
					if (typeof (c[1]) != "undefined") {
						if (c[1]) {
							if (c[1] < 1 || c[1] > picList.length) {
								c[1] = 1
							}
							return c[1]
						}
					}
				}
				return 0
			}
		};
		return controlPicture;
	}

	function load() {
		var ractive = new Ractive({
			el : '#xq-container',
			template : "#xq-template",
			data : {
				"islogin" : false,
				"img" : img
			},
			oncomplete : function() {
				$(".lpxq").mouseover(function() {
					$("#lpxq-bananer").css("color", "#ffffff");
				}).mouseout(function() {
					$("#lpxq-bananer").css("color", "#000000");
				});

				// 获取礼品详情数据
				getlpxqDate(function(data) {
					if (data.yyjf != null) {
						ractive.set("islogin", true);
					}
					ractive.set("o", data);
					var lpsltList = data.lpsltList;

					var firstSlt = "";
					var picnum = 0;
					if (lpsltList != null && lpsltList.length > 0) {
						firstSlt = img + lpsltList[0].fjdz;
						picnum = lpsltList.length;
					}
					ractive.set("firstSlt", firstSlt);
					picControl = initCpic(picnum, selectKey);
					var curPicPos = picControl.selectByurl();
					if (curPicPos) {
						selectKey = curPicPos;
					}
					$("#lpxxjs").html(data.lpjs);
					ractive.set("dhlpmc", dwArr[0]);
					$("#xqnr").css("display", "block");
				});
			}
		});
		ractive.on({
			// 立即兑换
			ljdh : function() {
				manager.isLogin(function(data) {
					window.location.href = Constants.consumer + "page/lpdh/qrdh.html?lpid=" + lpid + "&ywy=" + ywy;
				})
			},
			rightYd : function() {
				picControl.changeList(1);
			},
			leftYd : function() {
				picControl.changeList(0);
			},
			showPic : function(event) {
				var src = $(event.node).attr("src");
				ractive.set("firstSlt", src);
			}
		});
	}
	// 获取礼品详情数据
	function getlpxqDate(fn) {
		$.ajax({
			type : "get",
			url : Constants.csUrlPath + "lpdh/getLpxq?lpid=" + lpid + "&ywy=" + ywy,
			success : function(data) {
				fn.call("", data);
			}
		});
	}

	return {
		init : function() {
			load();
		}

	}
}();
$(document).ready(lpxqApp.init);